﻿using System;
using PSE.Deployment.Engine;
using PSE.Deployment.Engine.Enums;
using PSE.Deployment.Engine.Interfaces;

namespace Sinacor.Deployment.Setup.Wizard.Steps
{
    public class License : BaseStep
    {
        public StepNavigationAction NavigationAction { get; protected set; }
        private UI.License license;

        public License(IStepGroup parent)
            :base(parent)
        {
            this.Id = "Licence";

            this.ExecutionFinished += new EventHandler<PSE.Deployment.Engine.CustomEventArgs.ExecutionFinishedEventArgs>(License_ExecutionFinished);
            this.ErrorBehavior = StepErrorBehavior.NotifyParent;
            this.NavigationBehavior = StepNavigationBehavior.NextPreviousCancel;
        }

        void License_ExecutionFinished(object sender, PSE.Deployment.Engine.CustomEventArgs.ExecutionFinishedEventArgs e)
        {
            e.NavigationAction = this.NavigationAction;
        }

        public override void Execute()
        {
            license = new UI.License();
            license.ShowDialog();
                        
            this.NavigationAction = license.NavigationAction.GetValueOrDefault();
        }

        public override void Undo()
        {
            if (license != null)
                license.Close(false);
        }
    }
}
